<%!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

%><% > Autogen%>
#pragma once

#include <thrift/lib/cpp2/gen/module_types_h.h>

<%#program:frozen?%>
#include <thrift/lib/cpp/Frozen.h>
<%/program:frozen?%>

<%#program:thrift_includes%>
#include "<%program:include_prefix%><%program:name%>_types.h"
<%/program:thrift_includes%>
<%#program:cpp_includes%>
#include <%cpp_include%>
<%/program:cpp_includes%>

<%#program:structs?%>
namespace apache {
namespace thrift {
namespace tag {
<%#program:structs%>
<%#struct:fields%>
struct <%field:cpp_name%>;
<%/struct:fields%>
<%/program:structs%>
} // namespace tag
namespace detail {
<%#program:structs%>
<%#struct:fields%>
#ifndef APACHE_THRIFT_ACCESSOR_<%field:cpp_name%>
#define APACHE_THRIFT_ACCESSOR_<%field:cpp_name%>
APACHE_THRIFT_DEFINE_ACCESSOR(<%field:cpp_name%>);
#endif
<%/struct:fields%>
<%/program:structs%>
} // namespace detail
} // namespace thrift
} // namespace apache

<%/program:structs?%>
<% > module_types_h/declare_enums%>

<% > module_types_h/forward_declare%>

<% > module_types_h/typedefs%>

<% > module_types_h/hash_and_equal_to%>

<%#program:structs%>
<% > common/namespace_cpp2_begin%>

class <%struct:name%> <%!
%><%^struct:virtual%>final <%/struct:virtual%><%#struct:exception?%><%!
%>: public apache::thrift::TException<%/struct:exception?%> {
 private:
  friend struct ::apache::thrift::detail::st::struct_private_access;

  //  used by a static_assert in the corresponding source
  static constexpr bool __fbthrift_cpp2_gen_json = <%program:json?%>;
  static constexpr bool __fbthrift_cpp2_gen_nimble = <%program:nimble?%>;

 public:
  using __fbthrift_cpp2_type = <%struct:name%>;
  static constexpr bool __fbthrift_cpp2_is_union =
    <%#struct:union?%>true<%/struct:union?%><%^struct:union?%>false<%/struct:union?%>;

<%#struct:cpp_allocator%>
 public:
  using allocator_type = <%struct:cpp_allocator%>;
  allocator_type get_allocator() const {
<%#struct:cpp_allocator_via%>
    return this-><%struct:cpp_allocator_via%>.get_allocator();
<%/struct:cpp_allocator_via%>
<%^struct:cpp_allocator_via%>
    return __fbthrift_alloc;
<%/struct:cpp_allocator_via%>
  }
<%^struct:cpp_allocator_via%>
 private:
  FOLLY_ATTR_NO_UNIQUE_ADDRESS allocator_type __fbthrift_alloc;
<%/struct:cpp_allocator_via%>
<%/struct:cpp_allocator%>

 public:
<%#struct:union?%>
<% > module_types_h/union_enum%>


  <%struct:name%>()
      : type_(Type::__EMPTY__) {}

<% > module_types_h/union_copy_ctor%>

<% > module_types_h/union_assign_overload%>
  void __clear();

  <%#struct:virtual%>virtual <%/struct:virtual%>~<%struct:name%>() {
    __clear();
  }
<%#struct:virtual%>

<%/struct:virtual%>
<% > module_types_h/union_storage%>

<%^struct:cpp_noncomparable%>
<% > module_types_h/eq_overload%>
<% > module_types_h/union_operator_less%>
<%/struct:cpp_noncomparable%>
<% > module_types_h/union_setters%>

<% > module_types_h/union_getters%>
<% > module_types_h/union_mutables%>
<% > module_types_h/union_moves%>
<% > module_types_h/union_field_ref%>
  Type getType() const { return static_cast<Type>(type_); }

  template <class Protocol_>
  uint32_t read(Protocol_* iprot);
  template <class Protocol_>
  uint32_t serializedSize(Protocol_ const* prot_) const;
  template <class Protocol_>
  uint32_t serializedSizeZC(Protocol_ const* prot_) const;
  template <class Protocol_>
  uint32_t write(Protocol_* prot_) const;
 protected:
  template <class T>
  void destruct(T &val) {
    (&val)->~T();
  }

  storage_type value_;
  std::underlying_type_t<Type> type_;
<%/struct:union?%>
<%^struct:union?%>

<%#struct:is_large?%>
  <%struct:name%>();
<%/struct:is_large?%>
THRIFT_IGNORE_ISSET_USE_WARNING_BEGIN
<%^struct:is_large?%>
  <% > module_types_h/base_ctor%>
<%/struct:is_large?%>

<%#struct:exception?%><%#struct:message%>

  explicit <%struct:name%>(const std::string& __message) :
      <%struct:message%>(__message) {}

  explicit <%struct:name%>(std::string&& __message) :
      <%struct:message%>(std::move(__message)) {}
<%/struct:message%><%/struct:exception?%>
  // FragileConstructor for use in initialization lists only.
  [[deprecated("This constructor is deprecated")]]
  <%struct:name%>(apache::thrift::FragileConstructor<% > module_types_h/fragile_ctor_param_list%>);
<%#struct:cpp_noexcept_move_ctor%>
<%^struct:fields?%>
  <%struct:name%>(<%struct:name%>&& other) noexcept {}
<%/struct:fields?%>
<%#struct:fields?%>
<%#struct:is_large?%>
  <%struct:name%>(<%struct:name%>&& other) noexcept;
<%/struct:is_large?%>
<%^struct:is_large?%>
<% > module_types_h/move_ctor%>
<%/struct:is_large?%>
<%/struct:fields?%>
<%/struct:cpp_noexcept_move_ctor%>
<%^struct:cpp_noexcept_move_ctor%>

  <%struct:name%>(<%struct:name%>&&) = default;
<%/struct:cpp_noexcept_move_ctor%>
<%^struct:cpp_noncopyable%>
<%^struct:fields_contain_cpp_ref_unique_either?%>

  <%struct:name%>(const <%struct:name%>&) = default;
<%/struct:fields_contain_cpp_ref_unique_either?%>
<%#struct:fields_contain_cpp_ref_unique_either?%>
  <%struct:name%>(const <%struct:name%>& src);
<%/struct:fields_contain_cpp_ref_unique_either?%>
<%/struct:cpp_noncopyable%>

<%#struct:cpp_allocator%>
<% > module_types_h/alloc_extended_ctors%>
<%/struct:cpp_allocator%>

<%#struct:cpp_noexcept_move%>
  <%struct:name%>& operator=(<%struct:name%>&&) noexcept = default;
<%/struct:cpp_noexcept_move%>
<%^struct:cpp_noexcept_move%>
  <%struct:name%>& operator=(<%struct:name%>&&) = default;
<%/struct:cpp_noexcept_move%>
<%^struct:cpp_noncopyable%>
<%^struct:fields_contain_cpp_ref_unique_either?%>

  <%struct:name%>& operator=(const <%struct:name%>&) = default;
<%/struct:fields_contain_cpp_ref_unique_either?%>
<%#struct:fields_contain_cpp_ref_unique_either?%>
  <%struct:name%>& operator=(const <%struct:name%>& src);
<%/struct:fields_contain_cpp_ref_unique_either?%>
THRIFT_IGNORE_ISSET_USE_WARNING_END
<%/struct:cpp_noncopyable%>
  void __clear();
<%^struct:virtual%>
<%#struct:is_large?%>

  ~<%struct:name%>();

<%/struct:is_large?%>
<%/struct:virtual%>
<%#struct:virtual%>

<%^struct:is_large?%>
  virtual ~<%struct:name%>() {}
<%/struct:is_large?%>
<%#struct:is_large?%>
  virtual ~<%struct:name%>();
<%/struct:is_large?%>

<%/struct:virtual%>
<%#struct:fields?%>
<% > module_types_h/declare_members%>
<%/struct:fields?%>
<%^struct:cpp_noncomparable%>
<% > module_types_h/eq_overload%>
<% > module_types_h/struct_operator_less%>
<%/struct:cpp_noncomparable%>
<%#struct:fields?%>
<% > module_types_h/field_ref%>
<%^struct:no_getters_setters?%>
<% > module_types_h/getters_setters%>
<%/struct:no_getters_setters?%>
<%/struct:fields?%>

  template <class Protocol_>
  uint32_t read(Protocol_* iprot);
  template <class Protocol_>
  uint32_t serializedSize(Protocol_ const* prot_) const;
  template <class Protocol_>
  uint32_t serializedSizeZC(Protocol_ const* prot_) const;
  template <class Protocol_>
  uint32_t write(Protocol_* prot_) const;
<%#struct:exception?%>

  const char* what() const noexcept override {
<%#struct:message%>
    return <%struct:message%>.c_str();
<%/struct:message%>
<%^struct:message%>
    return "<% > common/namespace_cpp2%><%struct:name%>";
<%/struct:message%>
  }
<%/struct:exception?%>
<%/struct:union?%>
<%#struct:cpp_methods%>
  // user defined code (cpp2.methods = ...)
  <%struct:cpp_methods%>
<%/struct:cpp_methods%>

 private:
  template <class Protocol_>
  void readNoXfer(Protocol_* iprot);

  friend class ::apache::thrift::Cpp2Ops< <%struct:name%> >;
  friend void swap(<%struct:name%>& a, <%struct:name%>& b);
  <%#program:tablebased?%>
  <%^struct:union?%>
  friend constexpr ptrdiff_t (::apache::thrift::detail::fieldOffset<<%struct:name%>>)(std::int16_t fieldIndex);
  friend constexpr ptrdiff_t (::apache::thrift::detail::issetOffset<<%struct:name%>>)(std::int16_t fieldIndex);
  <%/struct:union?%>
  <%#struct:union?%>
  friend constexpr ptrdiff_t (::apache::thrift::detail::unionTypeOffset<<%struct:name%>>)();
  <%/struct:union?%>
  <%/program:tablebased?%>
};

template <class Protocol_>
uint32_t <%struct:name%>::read(Protocol_* iprot) {
  auto _xferStart = iprot->getCursorPosition();
  readNoXfer(iprot);
  return iprot->getCursorPosition() - _xferStart;
}

<% > common/namespace_cpp2_end%>

<% > module_types_h/frozen%>
<%/program:structs%>
<% > module_types_h/declare_union_types%><%!

%><%#program:tablebased?%>
namespace apache {
namespace thrift {
namespace detail {
<%#program:structs%>
template <>
struct TypeToInfo<
    ::apache::thrift::type_class::<%#struct:union?%>variant<%/struct:union?%><%^struct:union?%>structure<%/struct:union?%>,
    <% > common/namespace_cpp2 %><%struct:name%>> {
  static const ::apache::thrift::detail::TypeInfo typeInfo;
};
<%/program:structs%>
<%#program:enums%>
  template <>
    struct TypeToInfo<
        ::apache::thrift::type_class::enumeration,
        <% > common/namespace_cpp2%><%enum:name%>> {
    static const ::apache::thrift::detail::TypeInfo typeInfo;
  };
<%/program:enums%>
}}} // namespace apache::thrift::detail
<%/program:tablebased?%>
